package com.zzyl.common.utils.ai;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.core.auth.Auth;
import com.baidubce.qianfan.model.chat.ChatResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@RequiredArgsConstructor
@Component
public class AIModelInvoker {
    private final BaiduAIProperties baiduAIProperties;
    public String QianFanInvoker(String prompt){

        Qianfan qianfan = new Qianfan(Auth.TYPE_OAUTH, baiduAIProperties.getAccessKey(), baiduAIProperties.getSecretKey());

        // 指定模型
        ChatResponse resp = qianfan.chatCompletion()
                .model(baiduAIProperties.getModeName())
                .addMessage("user", prompt)
                .temperature(0.7)
                .maxOutputTokens(2000)
                .responseFormat("json_object")
                .execute();
        return resp.getResult();
    }
}
